<template>
		<view class="paysus">
			<view class="header">
				<view class="h">
					{{pay_result}}
				</view>
				<button @click="gotoidnex" class="btn_return" type="default" size="mini" >返回首页</button>
			</view>
			
		</view>
</template>

<script>
	import {mapMutations} from 'vuex'
	export default {
		data () {
			return {
				order_number: '',
				pay_result: '',
				wxorder_number: '',
				aliPayShopOrder: '',
				weiXinShopPay: ''
			}
		},
		methods: {
			...mapMutations(['closeAllCart']),
			gotoidnex () {
				uni.switchTab({
					url: '/pages/index/index'
				})
			},
			//  微信支付成功
			async wxxinpay () {
				console.log('ok')
				const {data: res} = await uni.$http.get(`/order/weixinpublic/${this.wxorder_number}`)
				console.log(res)
				if (res.code !== 200) {
						this.pay_result = res.message
						return	uni.showToast({
							title: res.message,
							duration: 1500,
							icon: 'none'
						})
				}
				uni.showToast({
					title: '支付成功',
					duration: 1500,
					icon: 'none'
				})
				this.pay_result = '支付成功,请不要重复支付'
			},
			/*
				商品支付宝支付
			*/
		   async aliPayShop () {
			   try {
				   const {data: res} = await uni.$http.get(`/shop/aliPaySelectPaySuccess/${this.aliPayShopOrder}`)
				   console.log(res)
				   if (res.status !== 1) return uni.showToast({
				   	icon: 'none',
					title: res.message,
					duration: 2000
				   })
				   this.pay_result = '支付成功,请不要重复支付'
				   uni.showToast({
				   	icon: 'none',
				   					title: '购买商品成功',
				   					duration: 2000
				   })
				   	this.closeAllCart()
					
				} catch (e) {
					uni.showToast({
						icon: 'error',
						duration: 2000,
						title: '未知错误'
					})
				}
		   },
		   /*
			  商品微信支付
		   */
		  async weiXinPayShop () {
			  try {
			  				   const {data: res} = await uni.$http.get(`/shop/weiXinSelectPaySuccess/${this.weiXinShopPay}`)
			  				   console.log(res)
			  				   if (res.status !== 1) return uni.showToast({
			  				   	icon: 'none',
			  					title: res.message,
			  					duration: 2000
			  				   })
			  				   this.pay_result = '支付成功,请不要重复支付'
			  				   uni.showToast({
			  				   	icon: 'none',
			  				   					title: '购买商品成功',
			  				   					duration: 2000
			  				   })
			  				   	this.closeAllCart()
			  					
			  				} catch (e) {
			  					uni.showToast({
			  						icon: 'error',
			  						duration: 2000,
			  						title: '未知错误'
			  					})
			  				}
		  }
		},
		onLoad(options) {
			if (options.aliPayShopOrder) {
				// 商品支付宝支付
				this.aliPayShopOrder = options.aliPayShopOrder
				this.aliPayShop()
			}
			if (options.weiXinShopPay) {
				this.weiXinShopPay = options.weiXinShopPay
				this.weiXinPayShop()
			}
			if (options.order_number) {
				this.order_number = options.order_number
				this.checkorder()
			} 
			else if (options.wxorder_number) {
				this.wxorder_number = options.wxorder_number
				this.wxxinpay()
			}	
			
		}
	}
</script>

<style scoped lang="scss">
	.paysus {
		width: 100%;
		height: 400px;
		background-color: #FFFFFF;
		.header {
			display: flex;
			align-items: center;
			justify-content: center;
			flex-direction: column;
			width: 100%;
			height: 100%;
			color: #FFFFFF;
			font-size: 16px;
			.h {
				color: #000000;
				font-size: 16px;
			}
			.btn_return {
				margin-top: 10px;
				background-color: #C00000;
				color: #FFFFFF;
			}
		}
	}
</style>

